bool CjAppChooserXMLConfigFile::GetRequiredAppsByIndex (long nIndex, IndexSet& reqIndexes)
{
	CString reqIDs, id, temp;
	int tokStart = 0;
	int index = -1;

	if (GetRequiredApps(nIndex, reqIDs))
	{
		id = reqIDs.Tokenize ( _T(",;"), tokStart);

		while (id != _T(""))
		{
			index = FindApp (id, temp);
			if (index != -1)
			{
				TRACE3 ("App index %d requires app index %d (%s)\n", nIndex, index, temp);
				reqIndexes.insert(index);
			}

			id = reqIDs.Tokenize ( _T(",;"), tokStart);
		}

		return true;
	}

	return false;
}

bool CjAppChooserXMLConfigFile::GetRequiredApps (long nIndex, CString& reqIDs)
{
	//Load the apps root node (if it's not already)
	LoadAppsNode ();

	CString strQuery;
	//Format the XPath query
	strQuery.Format (_T("%s[%d]"), APP_ELEMENTNAME, nIndex + 1);

	//Get the App element using the XPath query
	XmlElement eApp = m_eApps->selectSingleNode (strQuery.AllocSysString());

	//If found get the package and program IDs
	if (eApp)
	{
		_variant_t v1 = eApp->getAttribute (APP_REQUIRESATTRIBUTE);
		if (v1.vt == VT_BSTR)
		{
			reqIDs = v1.bstrVal;
			return true;
		}
		else
			reqIDs = _T("");
	}	
	
	return false;
}

	//	//Get the index of the application in the configuration file (this was stored when we created the item)
	//	pAppData = (APPDATA*)m_ctrlApps.GetItemData (hItem);
	//	nItemIndex = pAppData->index;
	//	
	//	//If the index is -1, the item is a group and doesn't effect the output so skip it
	//	if (nItemIndex > -1)
	//	{
	//		TRACE2 ("%d -> %s\n", nItemIndex, m_ctrlApps.GetItemText (hItem));
	//		indexes.insert (nItemIndex);

	//		if (m_xmlConfig.GetRequiredAppsByIndex (nItemIndex, reqIndexes))
	//			merge_sets (indexes, reqIndexes);
	//	}

	//	hItem = m_ctrlApps.GetNextCheckedItem (hItem);

	//	nItemIndex = -1;
	//	reqIndexes.clear();
	//}

//void COSDAppChooserDlg::SelectDependants(XHTMLTREEMSGDATA* data, BOOL check)
//{
//
//	if (data)
//	{
//
//		//Get the index of the application in the configuration file (this was stored when we created the item)
//		APPDATA* pAppData = (APPDATA*)m_ctrlApps.GetItemData (data->hItem);
//		int nItemIndex = pAppData->index;
//			
//		//If the index is -1, the item is a group and doesn't effect the output so skip it
//		if (nItemIndex > -1)
//		{
//			TRACE2 ("Checked Item with index %d: %s\n", nItemIndex, m_ctrlApps.GetItemText (data->hItem));
//
//			CString reqIDs;
//
//			if (m_xmlConfig.GetRequiredApps (nItemIndex, reqIDs))
//			{
//				CString id, appName;
//				int tokStart = 0;
//				HTREEITEM foundItem = 0;
//				int foundIndex = -1;
//				
//				id = reqIDs.Tokenize ( _T(",;"), tokStart);
//
//				while (id != _T(""))
//				{
//					if (m_xmlConfig.FindApp (id, appName) > -1)
//					{
//						TRACE3 ("	App index %d requires app %s(%s)\n", nItemIndex, appName, id);
//
//						foundItem = m_ctrlApps.FindItem (appName, 1, 0, 1, 1, data->hItem);
//
//						if (foundItem)
//						{
////							m_reqApps.AddTail (appName);
//							APPDATA* pReqItemData = (APPDATA*)m_ctrlApps.GetItemData (foundItem);
//
//							if (check)
//							{
//								if (pReqItemData->indexesReqBy.empty())
//								{
//									if (m_ctrlApps.GetCheck (foundItem))
//										pReqItemData->bPrevSelect = true;
//									else
//										pReqItemData->bPrevSelect = false;
//								}
//
//								m_ctrlApps.SetCheck(foundItem, 1);
//								m_ctrlApps.EnableItem(foundItem, false);
//
//								pReqItemData->indexesReqBy.insert(nItemIndex);
//
//								TRACE3 ("		Adding index %d to request list of %s (%d)\n", nItemIndex, appName, pReqItemData->indexesReqBy.size());
//								
//							}
//							else
//							{
//								pReqItemData->indexesReqBy.erase(nItemIndex);
//
//								TRACE3 ("		Removing index %d from request list of %s (%d)\n", nItemIndex, appName, pReqItemData->indexesReqBy.size());
//
//								if (!pReqItemData->bMandatory && pReqItemData->indexesReqBy.empty())
//								{
//									m_ctrlApps.EnableItem(foundItem, true);
//
//									if (pReqItemData->bPrevSelect == false)
//										m_ctrlApps.SetCheck(foundItem, 0);
//								}
//							}
//
//							if (pReqItemData->indexesReqBy.size() > 0)
//								m_ctrlApps.SetItemNote (foundItem, _T("Apps Depend on this one."));
//							else
//								m_ctrlApps.SetItemNote (foundItem, _T(""));
//						}
//
//						id = reqIDs.Tokenize ( _T(",;"), tokStart);
//					}
//				}
//
//			}
//
//			//if (check && firstCheck && !m_reqApps.IsEmpty ())
//			//{
//
//			//	CString reqApps, reqAppsHdr;
//
//			//	reqAppsHdr.LoadString (IDS_MSGREQAPPSHDR);
//			//	reqApps.LoadString (IDS_MSGREQAPPS);
//
//			//	reqAppsHdr.Insert (0, _T (" "));
//			//	reqAppsHdr.Insert (0, m_ctrlApps.GetItemText (data->hItem));
//
//			//	while (!m_reqApps.IsEmpty())
//			//	{
//			//		reqApps += _T ("\r\n- ");
//
//			//		reqApps += m_reqApps.GetHead ();
//			//		m_reqApps.RemoveHead ();
//
//			//	}
//
//			//	if (m_userSelect)
//			//	{
//
//			//		CBalloonMsg::ShowForCtrl (reqAppsHdr, reqApps, m_ctrlInfoIcon, m_hWarn);
//
//			//	}
//
//			//}
//
//		}
//	}
//
//}

	//elstApps = m_eApps->getElementsByTagName (APP_ELEMENTNAME);

	//Loop through the list
	//Not using a query to find it because the index of the app in the list
	//determines its installation priority
	//for (long nodeCount = 0; nodeCount < elstApps->length; nodeCount++)
	//{
	//	//Get the next node/e
	//	eApp = elstApps->nextNode ();

	//	//Make sure the element is valid, 0 is return if no more node exist in the list
	//	if (eApp != 0)
	//	{
	//		//Get the GUID of the current app e and check if it matches the
	//		//one that we are looking for
	//		_variant_t v = eApp->getAttribute (APP_IDATTRIBUTE);
	//		
	//		if (v.vt == VT_BSTR && CString(v.bstrVal) == strAppGUID)
	//		{
	//			//Get the name of the app that matches the GUID passed in
	//			//so it can be returned 
	//			_variant_t v2 = eApp->getAttribute (APP_NAMEATTRIBUTE);
	//			
	//			if (v2.vt == VT_BSTR)
	//				strAppName = v2.bstrVal;

	//			//Return the index of the app in the list
	//			return nodeCount;
	//		}
	//	}

	//}
	//App is not found